package zw_1601_1700.zw_1640_能否连接形成数组;

class Solution {

    public boolean canFormArray(int[] arr, int[][] pieces) {
        int n = arr.length, m = pieces.length;
        int[] hash = new int[110];
        for (int i = 0; i < m; i++) hash[pieces[i][0]] = i;
        for (int i = 0; i < n; ) {
            int[] cur = pieces[hash[arr[i]]];
            int len = cur.length, idx = 0;
            while (idx < len && cur[idx] == arr[i + idx]) idx++;
            if (idx == len) i += len;
            else return false;
        }
        return true;
    }
}